/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package service.views;

import com.openbrew.openbrewrf.views.CustomerView;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.PersistenceContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import service.AbstractFacade;

/**
 *
 * @author dchapman
 */
@Stateless
@Path("com.openbrew.openbrewrf.customerview")
public class CustomerViewFacadeREST extends AbstractFacade<CustomerView> {
    @PersistenceContext(unitName = "com.openBrew_openBrewRF_war_1.0PU")
    private EntityManager em;

    public CustomerViewFacadeREST() {
        super(CustomerView.class);
    }

    @PUT
    @Override
    @Consumes({"application/xml", "application/json"})
    public void edit(CustomerView entity) {
        super.edit(entity);
    }

    @GET
    @Path("{id}")
    @Produces({"application/xml", "application/json"})
    public CustomerView find(@PathParam("id") Integer id) {
        return super.find(id);
    }

    @GET
    @Override
    @Produces({"application/xml", "application/json"})
    public List<CustomerView> findAll() {
        return getEntityManager().createNamedQuery("CustomerView.findAll").getResultList();
        //return super.findAll();
    }

    @GET
    @Path("{from}/{to}")
    @Produces({"application/xml", "application/json"})
    public List<CustomerView> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
        return super.findRange(new int[]{from, to});
    }
    
    @GET
    @Path("runNamedQuery/{str}")
    @Override
    @Produces({"application/xml", "application/json"})
    public List<CustomerView> runNamedQuery(@PathParam("str") String str){
        return super.runNamedQuery(str);
    }

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
}
